/**
 * fileName:  FruitEfficacyRelationWriter.java
 * author:  lr
 * Company:  Cloudland Studio
 * Createdate:  2014-6-11 下午05:56:30
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-11          lr            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.write;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseWrite;
import org.cloudland.commercial.masterdata.store.entity.FruitEfficacyEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.EfficacyRelationEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.EfficacyRelationMapper;
import org.cloudland.util.Randoms;
import org.springframework.stereotype.Service;

/**
 * <pre>
 * 水果功效关系写操作
 * 使用 java.lang.Object#toString(), 或者 {@link java.lang.Character Character} 等标签
 * </pre>
 * 
 * @ClassName FruitEfficacyRelationWriter
 * @author lr
 * @version %I%, %G%
 * @see
 * @since JDK1.6
 * 
 */
@Service
public class FruitEfficacyRelationWriter implements
		DatabaseWrite<FruitEfficacyEntity> {

	@Resource(name = "efficacyRelationMapper")
	private EfficacyRelationMapper efficacyRelationMapper;

	public void save(FruitEfficacyEntity entity) {
		EfficacyRelationEntity daoEntity = new EfficacyRelationEntity();
		String uuid = Randoms.uuid();
		daoEntity.setFruitEfficacyId(uuid);
		daoEntity.setEfficacyId(entity.getEfficacyId());
		daoEntity.setEffcacyWeight(entity.getWeight());
		daoEntity.setFruitId(entity.getFruitId());
		daoEntity.setPartId(entity.getStructureId());
		daoEntity.setSort(entity.getSort());
		efficacyRelationMapper.add(daoEntity);
	}

	public void update(FruitEfficacyEntity entity) {
		EfficacyRelationEntity daoEntity = new EfficacyRelationEntity();
		daoEntity.setFruitEfficacyId(entity.getEfficacyId());
		daoEntity.setEfficacyId(entity.getEfficacyId());
		daoEntity.setEffcacyWeight(entity.getWeight());
		daoEntity.setFruitId(entity.getFruitId());
		daoEntity.setPartId(entity.getStructureId());
		daoEntity.setSort(entity.getSort());
		efficacyRelationMapper.update(daoEntity);
	}

	public void delete(FruitEfficacyEntity entity) {
		EfficacyRelationEntity daoEntity = new EfficacyRelationEntity();
		daoEntity.setFruitEfficacyId(entity.getEfficacyId());
		daoEntity.setEfficacyId(entity.getEfficacyId());
		daoEntity.setEffcacyWeight(entity.getWeight());
		daoEntity.setFruitId(entity.getFruitId());
		daoEntity.setPartId(entity.getStructureId());
		daoEntity.setSort(entity.getSort());
		efficacyRelationMapper.delete(daoEntity);
	}
	
	/**
	 * <pre>
	 * 根据水果编号删除结构功效
	 * </pre>
	 *
	 * @param fruitId   
	 */
	public void deleteByFruitId(String fruitId) {
		efficacyRelationMapper.deleteByFruitId(fruitId);
	}

}
